﻿using System.Linq.Expressions;

namespace FrameWork.DataHelper;

public static class QueryableExtensions
{
    /**
     * 数据库WhereIF查询
     */
    public static IQueryable<T> WhereIF<T>(this IQueryable<T> source, Expression<Func<T, bool>> predicate,
        bool condition) where T : class
    {
        return condition ? source.Where(predicate) : source;
    }

    /**
     * 数据库分页查询
     */
    public static IQueryable<T> Page<T>(this IQueryable<T> source, int pageIndex, int PageSize)
        where T : class
    {
        pageIndex = (pageIndex - 1) * PageSize;
        return source.Skip(pageIndex).Take(PageSize);
    }
}